<?php

/**
 * This is the model class for table "{{rapportEvaluation}}".
 *
 * The followings are the available columns in table '{{rapportEvaluation}}':
 * @property integer $id
 * @property string $security_key
 * @property string $status
 * @property string $pdf_original
 * @property string $pdf_final
 * @property integer $note
 * @property string $date_remise
 * @property integer $jour_retard
 * @property integer $confidentiel
 * @property string $resume_fr
 * @property string $resume_en
 * @property string $mot_cle_fr
 * @property string $mot_cle_en
 * @property integer $rapportMarksheet_id
 * @property double $plagiat_percentage
 *
 * The followings are the available model relations:
 * @property RapportMarksheet $rapportMarksheet
 * @property Stage[] $stages
 */
class RapportEvaluation extends CActiveRecord
{
	public $file;
	/**
	 * Returns the static model of the specified AR class.
	 * @return RapportEvaluation the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{rapportEvaluation}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('rapportMarksheet_id', 'required'),
			array('note, jour_retard, confidentiel, rapportMarksheet_id', 'numerical', 'integerOnly'=>true),
			array('plagiat_percentage', 'numerical'),
			array('security_key', 'length', 'max'=>32),
			array('status', 'length', 'max'=>7),
			array('pdf_original, pdf_final, mot_cle_fr, mot_cle_en', 'length', 'max'=>45),
			array('date_remise, resume_fr, resume_en', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, status, pdf_original, pdf_final, note, date_remise, jour_retard, confidentiel, resume_fr, resume_en, mot_cle_fr, mot_cle_en, rapportMarksheet_id, plagiat_percentage', 'safe', 'on'=>'search'),
			// The following rule is for download/upload file
			array('file','file','types'=>'pdf,doc','maxSize'=>'5000000','allowEmpty'=>true),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'rapportMarksheet' => array(self::BELONGS_TO, 'RapportMarksheet', 'rapportMarksheet_id'),
			'stages' => array(self::HAS_MANY, 'Stage', 'rapportEvaluation_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'security_key' => 'Security Key',
			'status' => 'Status',
			'pdf_original' => 'Pdf Original',
			'pdf_final' => 'Pdf Final',
			'note' => 'Note',
			'date_remise' => 'Date Remise',
			'jour_retard' => 'Jour Retard',
			'confidentiel' => 'Confidentiel',
			'resume_fr' => 'Resume Fr',
			'resume_en' => 'Resume En',
			'mot_cle_fr' => 'Mot Cle Fr',
			'mot_cle_en' => 'Mot Cle En',
			'rapportMarksheet_id' => 'Rapport Marksheet',
			'plagiat_percentage' => 'Plagiat Percentage',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('security_key',$this->security_key,true);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('pdf_original',$this->pdf_original,true);
		$criteria->compare('pdf_final',$this->pdf_final,true);
		$criteria->compare('note',$this->note);
		$criteria->compare('date_remise',$this->date_remise,true);
		$criteria->compare('jour_retard',$this->jour_retard);
		$criteria->compare('confidentiel',$this->confidentiel);
		$criteria->compare('resume_fr',$this->resume_fr,true);
		$criteria->compare('resume_en',$this->resume_en,true);
		$criteria->compare('mot_cle_fr',$this->mot_cle_fr,true);
		$criteria->compare('mot_cle_en',$this->mot_cle_en,true);
		$criteria->compare('rapportMarksheet_id',$this->rapportMarksheet_id);
		$criteria->compare('plagiat_percentage',$this->plagiat_percentage);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * This is invoked before the record is saved.
	 * @return boolean whether the record should be saved.
	 */
	protected function beforeSave()
	{
	    if(parent::beforeSave())
	    {
	        if($this->isNewRecord)
	            $this->date_remise=time();
	        return true;
	    }
	    else
	        return false;
	}
}